﻿using System;
using System.Windows.Automation;

namespace QuickUIT.Controls
{
    /// <summary>
    /// Represents a menu item control. 
    /// </summary>
    public class UIMenuItem : UIBaseControl
    {
        /// <summary>
        /// Gets the expand/collapse state of the control. 
        /// </summary>
        public new ExpandCollapseState? ExpandCollapseState
        {
            get { return base.ExpandCollapseState; }
        }

        /// <summary>
        /// Gets whether the menu item is expanded. 
        /// </summary>
        public bool IsExpanded
        {
            get
            {
                return (ExpandCollapseState.HasValue &&
                        ExpandCollapseState.Value == System.Windows.Automation.ExpandCollapseState.Expanded);
            }
        }

        /// <summary>
        /// Gets the toggle state of the current control. 
        /// </summary>
        public new ToggleState? ToggleState
        {
            get { return base.ToggleState; }
        }

        /// <summary>
        /// Gets whether the menu item is selected. 
        /// </summary>
        public new bool IsSelected
        {
            get { return base.IsSelected; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIMenuItem"/> class. 
        /// </summary>
        public UIMenuItem()
            : base(ControlType.MenuItem)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIMenuItem"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        public UIMenuItem(UIBaseControl parent)
            : base(parent, ControlType.MenuItem)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIMenuItem"/> class.
        /// </summary>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UIMenuItem(string locator)
            : base(null, ControlType.MenuItem, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIMenuItem"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UIMenuItem(UIBaseControl parent, string locator)
            : base(parent, ControlType.MenuItem, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIMenuItem"/> class.
        /// </summary>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UIMenuItem(AutomationElement control) : base(control, ControlType.MenuItem)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIMenuItem"/> class.
        /// </summary>
        /// <param name="parent">The parent of the control</param>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UIMenuItem(UIBaseControl parent, AutomationElement control) : base(parent, control, ControlType.MenuItem)
        {
        }

        /// <summary>
        /// Expands the menu item, displaying all its child nodes, controls or content. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new void Expand()
        {
            base.Expand();
        }

        /// <summary>
        /// Collapses the current menu item, hiding all its child nodes, controls or content. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new void Collapse()
        {
            base.Collapse();
        }

        /// <summary>
        /// Deselects any selected items and then selects the current menu item.
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new void Select()
        {
            base.Select();
        }

        /// <summary>
        /// Adds the current menu item to the collection of selected items. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new void AddToSelection()
        {
            base.AddToSelection();
        }

        /// <summary>
        /// Removes the current menu item to the collection of selected items. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new void RemoveFromSelection()
        {
            base.RemoveFromSelection();
        }

        /// <summary>
        /// Toggles the menu item. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        /// <remarks>A control will cycle through its ToggleState in this order: On, Off and, if supported, Indeterminate.</remarks>
        public new void Toggle()
        {
            base.Toggle();
        }

        /// <summary>
        /// Toggles on the menu item. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new void ToggleOn()
        {
            base.ToggleOn();
        }

        /// <summary>
        /// Toggles off the menu item. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new void ToggleOff()
        {
            base.ToggleOff();
        }

        /// <summary>
        /// Calls invoke a control to initiate or perform a single, unambiguous action that does not maintain state when activated.
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new void Invoke()
        {
            base.Invoke();
        }
    }
}
